package com.example.demo.web;


import com.example.demo.business.UserInfoBusiness;
import com.example.demo.dao.entity.UserInfo;
import com.example.demo.model.BaseResponse;
import com.example.demo.model.UserInfoVo;
import com.example.demo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 后台管理用户表 前端控制器
 * </p>
 *
 * @author jacheut
 * @since 2018-07-05
 */
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
    @Autowired
    private UserInfoBusiness userInfoBusiness;

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 并发访问test
     *
     * @param id
     * @param orderId
     */
    @RequestMapping("/callTest")
    public void callTest(Integer id, String orderId) {
        userInfoBusiness.concurrencyCall(id, orderId);
    }

    /**
     * 查询所有用户信息
     *
     * @param id
     * @param orderId
     * @return
     */
    @RequestMapping("/getUserInfos")
    public BaseResponse<List<UserInfoVo>> getUserInfos(Integer id, String orderId) {
        List<UserInfo> userInfoList = userInfoService.getAllUserInfos();
        return new BaseResponse<>(UserInfoVo.convertUserInfoList(userInfoList));
    }

    /**
     * 新增用户
     *
     * @param
     * @return
     */
    @RequestMapping("/addUserInfo")
    public BaseResponse getUserInfos(@RequestBody UserInfoVo userInfoVo) {
        userInfoService.addUserInfo(userInfoVo);
        return new BaseResponse<>();
    }
}

